跳到主要内容

AddCaption

Adds a caption paragraph after (or before) the current content control. 💡 Please note that the current content control must be in the document (not in the footer/header). And if the current content control is placed in a shape, then a caption is added after (or before) the parent shape.

Syntax

expression.AddCaption(additionalText, label, excludeLabel, numFormat, isBefore, headingLvl, captionSep);

expression - A variable that represents a ApiBlockLvlSdt class.

Parameters

NameRequired/OptionalData typeDefaultDescription
additionalTextRequiredstringThe additional text.
labelOptionalCaptionLabelString"Table"
excludeLabelOptionalbooleanfalseSpecifies whether to exclude the label from the caption.
numFormatOptionalCaptionNumberingFormat"Arabic"The possible caption numbering format.
isBeforeOptionalbooleanfalseSpecifies whether to insert the caption before the current content control (true) or after (false) (after/before the shape if it is placed in the shape).
headingLvlOptionalNumberThe heading level (used if you want to specify the chapter number). 💡 If you want to specify "Heading 1", then nHeadingLvl === 0 and etc.
captionSepOptionalCaptionSep"hyphen"The caption separator (used if you want to specify the chapter number).

Returns

boolean

Example

This example adds a caption paragraph after (or before) the current content control.

let doc = Api.GetDocument();
let blockLvlSdt = Api.CreateBlockLvlSdt();
let paragraph = Api.CreateParagraph();
let image = Api.CreateImage("https://static.onlyoffice.com/assets/docs/samples/img/onlyoffice_logo.png", 60 * 36000, 35 * 36000);
paragraph.AddDrawing(image);
blockLvlSdt.AddElement(paragraph, 0);
doc.AddElement(0, blockLvlSdt);
blockLvlSdt.AddCaption("", "Figure", false, "Arabic", false, undefined, "hyphen");